﻿using System;
using System.IO;
using LiteDB;

namespace BDSync.Domains.DataContext
{
    public class DBContext
    {
        private static LiteDatabase db;
        private static object lockobj = new object();
        private static readonly string DBName = "ConfigDB.db";
       
        public static LiteDatabase GetDB()
        {
            lock (lockobj)
            {
                if (db == null)
                {
                    var folder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DBConfig");
                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }
                    var dbPath = Path.Combine(folder, DBName);
                    db = new LiteDatabase(dbPath);
                }
                return db;
            }
        }


    }
}
